package fda.hash;

import fda.base.Constants;
import fda.base.Tuple;

public class Bucket {
	private int numberOfRecords;
	private int counter;
	
	private Tuple[] records;
	
	public Bucket() {
		InitBucket();
	}
	
	public void InitBucket() {
		numberOfRecords = Constants.MAX_TYPLES_IN_BLOCK;
		// create the the record array in bucket
		records = new Tuple[numberOfRecords];
		
		// set record counter in bucket to zero
		counter = 0;
	}
	
	// returns the records in the block
	public Tuple[] getTuplesInBucket() {
		return records;
	}
	
	// adds record to bucket
	public boolean AddRecord(Tuple record, int index) {
		if(counter < numberOfRecords) {
			records[counter] = record;
			counter++;
			return counter >= numberOfRecords;
		}
		
		throw new IllegalStateException("record lost because the bucket is full");
	}
}
